---
- name: Create the release tags in koji.
  hosts: compose-x86-01.stg.iad2.fedoraproject.org
  gather_facts: no
  vars_files:
    - /srv/web/infra/ansible/vars/all/00-FedoraCycleNumber.yaml
    - /srv/web/infra/ansible/vars/all/FedoraBranched.yaml
    - /srv/web/infra/ansible/vars/all/FedoraBranchedNumber.yaml
    - /srv/web/infra/ansible/vars/all/FedoraRawhideNumber.yaml
  vars:
    - appliance_build: [appliance-tools, bash, coreutils, grub, parted, perl, policycoreutils, selinux-policy, shadow-utils, sssd-client]
    - build: [bash, bzip2, coreutils, cpio, diffutils, fedora-release, findutils, gawk, glibc-minimal-langpack, grep, gzip, info, patch, redhat-rpm-config, rpm-build, sed, shadow-utils, tar, unzip, util-linux, which, xz]
    - livecd_build: [bash, coreutils, fedora-logos, fedora-release, livecd-tools, policycoreutils, python-dbus, sed, selinux-policy-targeted, shadow-utils, squashfs-tools, sssd-client, tar, unzip, util-linux, which, yum]
    - livemedia_build: [bash, coreutils, glibc-all-langpacks, lorax-lmc-novirt, selinux-policy-targeted, shadow-utils, util-linux]
    - srpm_build: [bash, fedora-release, fedpkg-minimal, glibc-minimal-langpack, gnupg2, redhat-rpm-config, rpm-build, shadow-utils]
    - release: f{{FedoraBranchedNumber}}
  collections:
  - ktdreyer.koji_ansible

  pre_tasks:
  - name: copy the koji.conf file with the correct variables
    template:
      src: koji.conf.j2
      dest: /etc/koji.conf
      owner: root
      group: root
      mode: 0644

  tasks:
  - name: create the main koji tag for {{release}}
    koji_tag:
      koji: koji
      name: "{{release}}"
      state: present
      perm: autosign
      groups:
        appliance-build: "{{appliance_build}}"
        build: "{{build}}"
        livecd-build: "{{livecd_build}}"
        livemedia-build: "{{livemedia_build}}"
        srpm-build: "{{srpm_build}}"
      extra:
        mock.package_manager: dnf
        mock.new_chroot : 0
    tags: rpm

  - name: create the {{release}} tags
    koji_tag:
      koji: koji
      name: "{{ item.name }}"
      state: present
      perm: "{{ item.perm }}"
      arches: "{{item.arches}}"
      inheritance:
      - parent: "{{ item.parent }}"
        priority: 0
    loop:
      - { name: "{{release}}-updates", perm: admin, parent: "{{release}}" , arches: ""}
      - { name: "{{release}}-updates-testing", perm: admin, parent: "{{release}}", arches: "" }
      - { name: "{{release}}-updates-pending", perm: admin, parent: "{{release}}", arches: "" }
      - { name: "{{release}}-override", perm: fedora-override, parent: "{{release}}", arches: "" }
      - { name: "{{release}}-updates-candidate", perm: '', parent: "{{release}}", arches: "" }
      - { name: "{{release}}-compose", perm: '', parent: "{{release}}", arches: "" }
      - { name: "{{release}}-updates-testing-pending", perm: 'autosign', parent: "{{release}}-updates-testing", arches: "" }
      - { name: "{{release}}-signing-pending", perm: 'autosign', parent: "{{release}}-updates-testing-pending", arches: "" }
      - { name: "{{release}}-pending", perm: '', parent: "{{release}}-updates", arches: "" }
      - { name: "{{release}}-build", perm: 'admin', parent: "{{release}}-override", arches: "armv7hl i686 x86_64 aarch64 ppc64le s390x" }
    tags: rpm

  - name: create the main infra tags
    koji_tag:
      koji: koji
      name: "{{ item.name }}"
      state: present
      perm: "{{ item.perm }}"
      inheritance:
      - parent: "{{ item.parent }}"
        priority: 0
      extra:
        tag2distrepo.enabled: "true"
        tag2distrepo.keys: 47dd8ef9
    loop:
      - { name: "{{release}}-infra", perm: 'infra', parent: "{{release}}-build", arches: "" }
      - { name: "{{release}}-infra-stg", perm: 'infra', parent: "{{release}}-infra", arches: "" }
    tags: infra

  - name: create the other infra tags
    koji_tag:
      koji: koji
      name: "{{ item.name }}"
      state: present
      perm: "{{ item.perm }}"
      inheritance:
      - parent: "{{ item.parent }}"
        priority: 0
    loop:
      - { name: "{{release}}-infra-candidate", perm: 'infra', parent: "{{release}}-infra-stg", arches: "" }
      - { name: "{{release}}-infra-build", perm: 'infra', parent: "{{release}}-infra-stg", arches: "" }
    tags: infra


  - name: create the container tag
    koji_tag:
      koji: koji
      name: "{{release}}-container"
      state: present
    tags: container


  - name: create the container build tag
    koji_tag:
      koji: koji
      name: "{{release}}-container-build"
      state: present
      arches: "x86_64"
      inheritance:
      - parent: "{{release}}-container"
        priority: 0
    tags: container

  - name: create the openh264 tags
    koji_tag:
      koji: koji
      name: "{{release}}-openh264"
      state: present
      inheritance:
      - parent: "{{release}}"
        priority: 0
    loop:
      - { name: "{{release}}-modularity", perm: '', parent: "", arches: "" }
      - { name: "{{release}}-container-build", perm: '', parent: "{{release}}-container", arches: "x86_64" }
    tags: openh264


  - name: create the main coreos tag
    koji_tag:
      koji: koji
      name: "{{release}}-coreos-continuous"
      state: present
      arches: "x86_64 aarch64 ppc64le s390x"
      extra:
        tag2distrepo.enabled: "true"
    tags: coreos

  - name: create the coreos-pool tag
    koji_tag:
      koji: koji
      name: "coreos-pool"
      state: present
      arches: "x86_64 aarch64 ppc64le s390x"
      extra:
        tag2distrepo.keys: "429476b4 cfc659b9 3c3359c4 12c944d0"
    tags: coreos

  - name: create the other coreos tags
    koji_tag:
      koji: koji
      name: "{{release}}-coreos-signing-pending"
      state: present
      arches: "x86_64 aarch64 ppc64le s390x"
      inheritance:
      - parent: "coreos-pool"
        priority: 0
      extra:
        tag2distrepo.enabled: "true"
    tags: coreos

  - name: create the main modularity tags
    koji_tag:
      koji: koji
      name: "{{release}}-modular"
      state: present
      perm: autosign
      extra:
        mock.package_manager: dnf
    tags: modularity

  - name: create the rest of the modularity tags
    koji_tag:
      koji: koji
      name: "{{ item.name }}"
      state: present
      perm: "{{ item.perm }}"
      arches: "{{item.arches}}"
      inheritance:
      - parent: "{{ item.parent }}"
        priority: 0
    loop:
      - { name: "{{release}}-modular-updates", perm: admin, parent: "{{release}}-modular" , arches: ""}
      - { name: "{{release}}-modular-updates-candidate", perm: '', parent: "{{release}}-modular-updates", arches: "" }
      - { name: "{{release}}-modular-updates-testing", perm: admin, parent: "{{release}}-modular-updates", arches: "" }
      - { name: "{{release}}-modular-updates-testing-pending", perm: 'autosign', parent: "{{release}}-modular-updates-testing", arches: "" }
      - { name: "{{release}}-modular-updates-pending", perm: admin, parent: "{{release}}-modular-updates", arches: "" }
      - { name: "{{release}}-modular-signing-pending", perm: 'autosign', parent: "{{release}}-modular-updates-testing-pending", arches: "" }
      - { name: "{{release}}-modular-override", perm: fedora-override, parent: "{{release}}-modular-updates", arches: "" }
      - { name: "{{release}}-modular-pending", perm: '', parent: "{{release}}-modular-updates", arches: "" }
    tags: modularity


  - name: add the modularity external repo
    koji_external_repo:
      koji: koji
      name: "{{release}}-build"
      url: "https://kojipkgs.fedoraproject.org/repos/{{release}}-build/latest/$arch/"
      state: present
    tags: modularity


  - name: create the module-{{release}}-build tag
    koji_tag:
      koji: koji
      name: "module-{{release}}-build"
      state: present
      inheritance:
      - parent: "module-package-list"
        priority: 0
      external_repos:
        - repo: "{{release}}-build"
          priority: 5
    tags: modularity


  - name: create the {{release}} target
    koji_target:
      koji: koji
      name: "{{release}}"
      build_tag: "{{release}}-build"
      dest_tag: "{{release}}-updates-candidate"
    tags: rpm


  - name: create the {{release}}-candidate target
    koji_target:
      koji: koji
      name: "{{release}}-candidate"
      build_tag: "{{release}}-build"
      dest_tag: "{{release}}-updates-candidate"
    tags: rpm


  - name: create the {{release}}-infra target
    koji_target:
      koji: koji
      name: "{{release}}-infra"
      build_tag: "{{release}}-infra-build"
      dest_tag: "{{release}}-infra-candidate"
    tags: infra


  - name: create the {{release}}-container-candidate target
    koji_target:
      koji: koji
      name: "{{release}}-container-candidate"
      build_tag: "{{release}}-container-build"
      dest_tag: "{{release}}-container-updates-candidate"
    tags: container


  - name: create the rawhide target
    koji_target:
      koji: koji
      name: "rawhide"
      build_tag: "f{{FedoraRawhideNumber}}-build"
      dest_tag: "f{{FedoraRawhideNumber}}-updates-candidate"
    tags: rawhide

  - name: create the rawhide container target
    koji_target:
      koji: koji
      name: "rawhide-container-candidate"
      build_tag: "f{{FedoraRawhideNumber}}-container-build"
      dest_tag: "f{{FedoraRawhideNumber}}-container"
    tags: rawhide


  - name: Change the rawhide tag inheritance
    koji_tag_inheritance:
      koji: koji
      parent_tag: "f{{FedoraRawhideNumber}}"
      child_tag: rawhide
      priority: 0
    tags: rawhide
